package com.yjs.ppjokedemo.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.luck.picture.lib.adapter.holder.VideoViewHolder;
import com.yjs.ppjokedemo.MyLinearLayoutManager;
import com.yjs.ppjokedemo.R;
import com.yjs.ppjokedemo.bean.VideoProduct;
import com.yjs.ppjokedemo.databinding.ItemHomeVideoBinding;

public class VideoListAdapter extends ListAdapter<VideoProduct,VideoListAdapter.VideoViewHolder> {

    VideoInterface mVideoInterface;
    MyLinearLayoutManager mLinearLayoutManager;
    VideoListAdapter mVideoListAdapter;
    public VideoListAdapter(VideoInterface videoInterface) {
        super(VideoProduct.itemCallback);
        this.mVideoInterface = videoInterface;
    }

    @Override
    public VideoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        ItemHomeVideoBinding itemHomeVideoBinding = ItemHomeVideoBinding.inflate(layoutInflater,parent,false);
        itemHomeVideoBinding.setVideoInterface(mVideoInterface);
        return new VideoViewHolder(itemHomeVideoBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull VideoListAdapter.VideoViewHolder holder, int position) {
        VideoProduct videoProduct = getItem(position);
        holder.videoBinding.setProduct(videoProduct);
        //问题2
        holder.videoBinding.gsy.setUp(videoProduct.getVideoUrl(),false,"");
        holder.videoBinding.gsy.getBackButton().setVisibility(View.GONE);
        holder.videoBinding.gsy.getFullscreenButton().setVisibility(View.GONE);
        holder.videoBinding.gsy.setNestedScrollingEnabled(false);

//        holder.videoBinding.gsy.setOnScrollChangeListener(new View.OnScrollChangeListener() {
//            @Override
//            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
//                int firstVisibleItemPosition = mLinearLayoutManager.findFirstVisibleItemPosition();
//
//
//            }
//        });
        holder.videoBinding.llVideo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("name",videoProduct.getId());
                bundle.putString("ivtou",videoProduct.getImageUrl());
                bundle.putString("videoUrl",videoProduct.getVideoUrl());

                ARouter.getInstance()
                        .build("/app/SofaVideoDetailActivity")
                        .withBundle("dataBean",bundle)
                        .navigation(v.getContext());
            }
        });


    }

    static class VideoViewHolder extends RecyclerView.ViewHolder {
        ItemHomeVideoBinding videoBinding;

        public VideoViewHolder(ItemHomeVideoBinding itemHomeVideoBinding){
            super(itemHomeVideoBinding.getRoot());
            this.videoBinding = itemHomeVideoBinding;
        }
    }

    public interface VideoInterface{

    }
}
